package com.link.ppt.Model.Impl;


import com.link.ppt.Api.UserService;
import com.link.ppt.Model.Bean.BaseBean;
import com.link.ppt.Model.Bean.ExpertFieldBean;
import com.link.ppt.Model.Bean.PersonalInfoBean;
import com.link.ppt.Model.Bean.SimpleUserInfoBean;
import com.link.ppt.Model.IUserModel;
import com.link.ppt.Utils.MD5Utils;
import com.link.ppt.Utils.ServiceFactory;
import com.link.ppt.Utils.TransformUtils;

import java.util.HashMap;
import java.util.Map;

import okhttp3.RequestBody;
import rx.Observable;

/**
 * 用户相关接口的所有实现
 * Created by liucxu on 2017/7/11.
 */

public class UserModelImpl implements IUserModel {

    /**
     * 获取登录验证码
     * @param mobile
     * @param countryCode
     * @return
     */
    @Override
    public Observable<BaseBean> GetVerificationCode(String mobile,String countryCode) {
        HashMap<String,String> params=new HashMap<>();
        params.put("mobile",mobile);
        params.put("countryCode",countryCode);
        params.put("verify", MD5Utils.GetMD5Value("sendVerificationPPTSecurityData"+mobile));
        params.put("type","mobileLogin");
        params.put("task","sendVerification");
        return ServiceFactory.GetInstance().createService(UserService.class).GetVerificationCode(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    /**
     * 验证码登录
     * @param mobile
     * @param verificationCode
     * @return
     */
    @Override
    public Observable<SimpleUserInfoBean> LoginByCode(String mobile,String verificationCode) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","loginByCode");
        params.put("mobile",mobile);
        params.put("code",verificationCode);
        return ServiceFactory.GetInstance().createService(UserService.class).LoginByCode(params).compose(TransformUtils.<SimpleUserInfoBean>defaultSchedulers());
    }

    @Override
    public Observable<SimpleUserInfoBean> RegisterUser(Map<String, RequestBody> params) {
        return ServiceFactory.GetInstance().createService(UserService.class).RegisterUser(params).compose(TransformUtils.<SimpleUserInfoBean>defaultSchedulers());
    }

    @Override
    public Observable<ExpertFieldBean> requestIndustry() {
        HashMap<String, String> params = new HashMap<>();
        params.put("task", "queryIndustryList");
        return ServiceFactory.GetInstance().createService(UserService.class).requestIndustry(params).compose(TransformUtils.<ExpertFieldBean>defaultSchedulers());
    }

    @Override
    public Observable<PersonalInfoBean> RequestUserInfo() {
        HashMap<String, String> params = new HashMap<>();
        params.put("task", "queryUserInfo");
        return ServiceFactory.GetInstance().createService(UserService.class).RequestUserInfo(params).compose(TransformUtils.<PersonalInfoBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> EditUserInfo(Map<String, RequestBody> params){
        return ServiceFactory.GetInstance().createService(UserService.class).EditUserInfo(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }
}
